from django.db import models

class Order( models.Model ):
    # Order information
    orderID = models.CharField( max_length=6, unique=True )
    cpID = models.CharField( max_length=6 )
    professor = models.CharField( max_length=64 )

    # Order production
    status = models.CharField( max_length=16, blank=True )
    producingCenter = models.ForeignKey( 'Center', blank=True )
    dueDateTime = models.DateTimeField( blank=True )

    # Order delivery
    deliveryAddress = models.ForeignKey( 'Address', blank=True )

    def __unicode__( self ):
        return '%s-%s %s' % ( self.cpID, self.orderID, self.professor )

    def __repr__( self ):
        return '<Order: %s>' % ( self.__unicode__() )


class Center( models.Model ):
    number = models.CharField( max_length=4, unique=True )
    name = models.CharField( max_length=64 )
    email = models.EmailField()
    address = models.ForeignKey( 'Address', blank=True )

    def __unicode__( self ):
	return '%s %s' % ( self.number, self.name )   

    def __repr__( self ):
        return '<Center: %s>' % ( self.__unicode__() )


class Address( models.Model ):
    name = models.CharField( max_length=64 )
    contact = models.CharField( max_length=32, blank=True )
    phone = models.CharField( max_length=12 )
    street = models.CharField( max_length=256 )
    street2 = models.CharField( max_length=16, blank=True )
    city = models.CharField( max_length=32 )
    state = models.CharField( max_length=2 )
    zip = models.CharField( max_length=5 )
    
    def __unicode__( self ):
	return self.name 

    def __repr__( self ):
        return '<Address: %s>' % ( self.__unicode__() )
